package elitech.vietnam.myfashion.extend;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
import elitech.vietnam.myfashion.MainActivity;
import elitech.vietnam.myfashion.view.BestGridView;
import elitech.vietnam.myfashion.view.CategoriesView;
import elitech.vietnam.myfashion.view.MyShoppingView;
import elitech.vietnam.myfashion.view.MyStyleView;
import elitech.vietnam.myfashion.view.SettingView;
import elitech.vietnam.myfashion.view.StylerView;

public class ViewPagerAdapter extends PagerAdapter {
	private MainActivity mContext;
	private int mCount;
	
	public CategoriesView mCategoriesView;
	public BestGridView mBestGridView;
	public MyStyleView mMyStyleView;
	public StylerView mStylerView;
	
	public ViewPagerAdapter(MainActivity context) {
		this.mContext = context;
		if (mContext.mUser != null)
			mCount = 6;
		else
			mCount = 4;
	}

	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}

	@Override
	public View instantiateItem(ViewGroup container, int position) {
		View view = new View(mContext);
		if (mContext.mUser != null)
			switch (position) {
			case 0:
				mBestGridView = new BestGridView(mContext);
				view = mBestGridView;
				break;
			case 1:
				mCategoriesView = new CategoriesView(mContext);
				view = mCategoriesView;
				break;
			case 2:
				mContext.mMyShoppingView = new MyShoppingView(mContext);
				view = mContext.mMyShoppingView;
				break;
			case 3:
				mStylerView = new StylerView(mContext);
				view = mStylerView;
				break;
			case 4:
				mMyStyleView = new MyStyleView(mContext);
				view = mMyStyleView;
				break;
			case 5:
				view = new SettingView(mContext);
				break;
			}
		else
			switch (position) {
			case 0:
				mBestGridView = new BestGridView(mContext);
				view = mBestGridView;
				break;
			case 1:
				mCategoriesView = new CategoriesView(mContext);
				view = mCategoriesView;
				break;
			case 2:
				mStylerView = new StylerView(mContext);
				view = mStylerView;
				break;
			case 3:
				view = new SettingView(mContext);
				break;
			}
		
		container.addView(view, LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);
		return view;
	}

	@Override
	public int getCount() {
		return mCount;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}
}
